package com.cjw.campus.core.controller;

import com.cjw.campus.core.result.JsonResult;
import com.cjw.campus.core.utils.UploadUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/common/upload")
@Tag(name = "上传文件管理接口")
public class UploadController {

    @PostMapping("/single")
    @Operation(summary = "上传文件", security = { @SecurityRequirement(name = "Authorization")})
    public JsonResult upload (@RequestPart("file") MultipartFile file) {
        String path = UploadUtil.uploadFile(file);
        return JsonResult.ok(path);
    }

    @PostMapping("/uploads")
    @Operation(summary = "上传多文件", security = { @SecurityRequirement(name = "Authorization")})
    public JsonResult uploadFiles (@RequestPart("file") MultipartFile[] files) {
        List path = UploadUtil.uploadFiles(files);
        return JsonResult.ok(path);
    }

}
